import { ref } from 'vue'
import { getBillInfo } from '@/api/order'

/**
 * 获取开票信息
 */
export default () => {
  // 获取信息加载
  const getBillInfoLoading = ref(false)

  // 开票信息
  const info = ref<OrderBillInfo | null>({
    header: '',
    headType: 1,
    ticketMoney: 0,
    ticketTaxNumber: '',
    ticketType: 1,
    id: '',
    applyTime: '',
    openTicketTime: '',
    email: '',
    openTicketStatus: 1,
    remark: '',
  })

  /**
   * 获取信息
   * @param {String} orderId - 工单id
   */
  const getInfo = async (orderId: string) => {
    getBillInfoLoading.value = true
    const res = await getBillInfo(orderId)
    getBillInfoLoading.value = false
    if (res.data.code === 20000) {
      info.value = res.data.data.row
      return ''
    }
    return res.data.message
  }

  return {
    info,
    getBillInfoLoading,
    getInfo,
  }
}
